﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CI.Models;
using CI.Models.Production;
using CI.Models.Data;
using CI.ViewModels.Interfaces;
using GongSolutions.Wpf.DragDrop;

namespace CI.ViewModels.Commerce
{
    public class BuyItemsVertexViewModel : ModelBase, IJobViewModel, IDropTarget
    {
        public BuyItemsJob Job { get; private set; }
        public IDiagramViewModel ParentModel { get; private set; }

        public BuyItemsVertexViewModel(BuyItemsJob job, IDiagramViewModel parentModel)
        {
            Job = job;
            ParentModel = parentModel;
        }

        public void DragOver(IDropInfo dropInfo)
        {
            if (dropInfo.Data is Item)
            {
                dropInfo.Effects = System.Windows.DragDropEffects.Copy;
            }
            else
            {
                dropInfo.IsNotHandled = true;
            }
        }

        public void Drop(IDropInfo dropInfo)
        {
            if (dropInfo.Data is Item)
            {
                var i = dropInfo.Data as Item;

                var eI = Job.Items.Where(j => j.Item.TypeID == i.TypeID).FirstOrDefault();

                if (eI != null) eI.Total++;
                else Job.Items.Add(new Models.Production.Interfaces.QuantifiedItem(dropInfo.Data as Item));
            }
        }
    }
}
